package main

import (
	"crypto/tls"
	"fmt"
	"net/http"
	"webhook/pkg"
)

func main() {
	// Read certificate file and private key file
	cert, err := tls.LoadX509KeyPair("./ca/webhook.crt", "./ca/webhook.key")
	if err != nil {
		fmt.Printf("get cert fail.err is :%v", err)
		panic(err)
	}

	// Creating a TLS Configuration
	tlsConfig := &tls.Config{
		Certificates: []tls.Certificate{cert},
		//ClientCAs:    caCertPool,
		//ClientAuth:   tls.RequireAndVerifyClientCert,
	}
	// Create an HTTP server
	server := &http.Server{
		Addr:      ":9443",
		TLSConfig: tlsConfig,
	}

	// start services
	http.Handle("/changePodScheduler", pkg.NewWebhookHandler())
	if err := server.ListenAndServeTLS("", ""); err != nil {
		fmt.Printf("server start fail,err is:%v", err)
		panic(err)
	}
}
